package com.ggggeeennn.studentUser.service.Impl;

import com.ggggeeennn.common.utils.PageUtils;
import com.ggggeeennn.score.mapper.ScoreMapper;
import com.ggggeeennn.student.domain.Student;
import com.ggggeeennn.student.mapper.StudentManageMapper;
import com.ggggeeennn.studentUser.mapper.StudentScoreMapper;
import com.ggggeeennn.studentUser.service.StudentScoreService;
import com.ggggeeennn.score.domain.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentScoreServiceImpl implements StudentScoreService {

    @Autowired
    private StudentManageMapper studentManageMapper;
    @Autowired
    private StudentScoreMapper studentScoreMapper;
    @Autowired
    private ScoreMapper scoreMapper;
    //获取某学生的分数列表
    @Override
    public List<Score> getScoreListByUserId(Long userId, Integer pageNum, Integer pageSize){
        Student student=studentManageMapper.selectStudentByUserId(userId);
        PageUtils.startPage(pageNum,pageSize);
        List< Score> list=studentScoreMapper.getScoreListByUserId(student.getStudentId());
        return list;
    }

    //某用户提交考试
    @Override
    public int submitExam(Score score) {
        //先通过userId获取studentId
        Student student=studentManageMapper.selectStudentByUserId(score.getUserId());
        score.setStudentId(student.getStudentId());
        score.setStudentName(student.getStudentName());
        return scoreMapper.insertScore(score);
    }
}
